<?php

require_once 'SmartL/Zend/Controller/Action.php';
require_once 'Db/Shop/Record/User.php';
require_once 'SmartL/Zend/Paginator/Adapter/Doctrine.php';
require_once 'Zend/Paginator.php';

class Admin_UsersController extends SmartL_Zend_Controller_Action
{
    public function listAction ()
    {
        // Parametry: stránka = 1
        $query = new Doctrine_Query();
        $query->parseDqlQuery($this->config->getAction("list")->getSelection("list")->getDql("Db_Shop_Record_User"));
        $paginator = new Zend_Paginator( new SmartL_Zend_Paginator_Adapter_Doctrine($query, Doctrine::HYDRATE_RECORD) );
        $paginator->setCurrentPageNumber($this->_getParam('page'));
        $paginator->setItemCountPerPage(4);
        $this->view->users = $paginator;
    }
    // @priority low
    public function userDetailAction ()
    {
        // Parametry: id uživatele
        if ($this->_hasParam('id')) {
            $query = new Doctrine_Query();
            $this->view->user = $query->from('Db_Shop_Record_User u')->select('u.*')->where('u.id = ?', $this->_getParam('id'))->execute()->getFirst();
        }
    }
    public function removeUserAction ()
    {
        // Parametry: id uživatele  
        if ($this->_hasParam('id')) {
            $query = new Doctrine_Query();
            $query->delete()->from('Db_Shop_Record_User u')->where('u.id = ?', $this->_getParam('id'))->execute();
        }
        $this->_helper->redirector->goto("list", "Users");
    }
}

